<template>
  <div class="login">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>权限管理系统</span>
      </div>
      <el-form
        :model="form"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="UserName">
          <el-input v-model="form.UserName"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="Pwd">
          <el-input v-model="form.Pwd"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="login('ruleForm')">注册</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
//命名导入
import { Register } from "../apis/admin";
export default {
  //数据
  data() {
    return {
      form: {
        UserName: "",
        Pwd: "",
        ValidateCode: "",
      },
      rules: {
        UserName: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        Pwd: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  //方法
  methods: {
    login(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // this.axios
          //   .post("http://localhost:11708/api/Admin/Login", this.form)
          //   .then((res) => {
          //     if (res.data.user.Code == 2) {
          //       this.$message.success("注册成功！");
          //     } else {
          //       this.$message.error(res.data.user.Message);
          //     }
          //   });
          Register(this.form).then((res) => {
            if (res.data.Code == 0) {
              this.$message.success("注册成功！");
              this.$router.push("/LoginParent");
            } else {
              this.$message.error(res.data.Message);
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
  //勾子函数
  created() {
    console.log(process.env);
  },
};
</script>
<style>
.login {
  width: 100%;
  height: 100%;
  background: #31c0c4;
  overflow: hidden;
}
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 480px;
  margin: 0 auto;
  margin-top: 15em;
}
</style>